import { request } from '../../../services/request';
import { SrnPickQueryParams, SrnPickResponse } from './types';

export const querySrnPick = async (params: SrnPickQueryParams): Promise<SrnPickResponse> => {
    console.log('请求参数:', params);

    try {
        const response = await request('/app/wms/srn/pick/queryPick', {
            method: 'POST',
            body: JSON.stringify(params),
        });

        console.log('接口返回:', response);
        return response;
    } catch (error) {
        console.error('查询 ASN 失败:', error);
        throw error;
    }
};

export const confirmSrnPick = async (params: {
    id?: string;
    tray_list?: { tray_num: string; quantity: string | number }[];
    sn_list?: string[];
    pick_quantity?: string;
    bus_num?: string;
    product_id?: string;
    sku_id?: string;
}): Promise<any> => {
    console.log('确认拣货请求参数:', params);

    try {
        const response = await request('/app/wms/srn/pick/pick', {
            method: 'POST',
            body: JSON.stringify(params),
        });

        console.log('确认拣货接口返回:', response);
        return response;
    } catch (error) {
        console.error('确认拣货失败:', error);
        throw error;
    }
};

export const getBodyListByBusNum = async (bus_num: string): Promise<any> => {
    try {
        const response = await request('/app/wms/srn/getBodyListByBusNum', {
            method: 'POST',
            body: JSON.stringify({ bus_num }),
        });
        return response;
    } catch (error) {
        console.error('获取产品列表失败:', error);
        throw error;
    }
};

export const getProductSkuList = async (product_id: string): Promise<any> => {
    try {
        const response = await request('/app/wms/srn/getProductSkuList', {
            method: 'POST',
            body: JSON.stringify({ product_id }),
        });
        return response;
    } catch (error) {
        console.error('获取SKU列表失败:', error);
        throw error;
    }
};

export const getSuggestOutStoreShelfNum = async (params: {
    product_id: string;
    sku_id: string;
    quantity: number;
}): Promise<any> => {
    try {
        const response = await request('/app/wms/srn/pick/getSuggestOutStoreShelfNum', {
            method: 'POST',
            body: JSON.stringify(params),
        });
        return response;
    } catch (error) {
        console.error('获取推荐储位失败:', error);
        throw error;
    }
};
